package com.net.retrofits.use.manager.push;


import com.net.retrofits.common.BaseNetSource;
import com.net.retrofits.common.RequestBack;
import com.net.retrofits.data.UrlManger;
import com.net.retrofits.manager.BaseAbstractManager;
import com.net.retrofits.use.req.push.HWPushReq;

import java.util.HashMap;

import retrofit2.Retrofit;


/**
 * 获取凭证，有效期5分钟
 * https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References-V5/account-obtain-token_hms_reference-0000001050048618-V5
 */
public class HWPushTokenManager extends BaseAbstractManager {
    public HWPushTokenManager(RequestBack requestBack) {
        super(requestBack);
    }


    private HWPushReq loginBeanReq;

    @Override
    protected void init() {
        loginBeanReq = new HWPushReq();
        setBaseReq(loginBeanReq);
    }

    private String appId;

    public void setAppId(String appId) {
        this.appId = appId;
    }

    private String token = "Bearer CF3Xl2XV6jMKZgqYSZFws9IPlgDvxqOfFSmrlmtkTRupbU2VklvhX9kC9JCnKVSDX2VrDgAPuzvNm3WccUIaDg==";

    public void setToken(String token) {
        this.token = "Bearer " + token;
    }

    public void setReqData(HWPushReq loginBeanReq) {
        this.loginBeanReq = loginBeanReq;
        setBaseReq(loginBeanReq);
    }

    @Override
    protected void request(Retrofit retrofit, String other) {
        HashMap map = getHeadMap();
        if (token != null && !token.isEmpty()) {
            map.put("Authorization", token);
        }
        HWPushApi service = new BaseNetSource().getRetrofit(new UrlManger()).create(HWPushApi.class);
       // Call<UseResultObject<HWPushResult>> call = service.poshToken(appId, map, loginBeanReq);
        /*call.enqueue(new RequestResultListener<UseResultObject<HWPushResult>>(this, loginBeanReq) {
            @Override
            public Object getObject(Response<UseResultObject<HWPushResult>> response) {
                UseResultObject<HWPushResult> body = response.body();
                HWPushResult obj = body.getObj();
                return obj;
            }
        });*/
    }


}
